import {BaseApi} from "./BaseApi.ts";
import {buildFavorFolder} from "../types/Favor.ts";


export class FavorApi extends BaseApi {
    // 查询收藏夹
    folderList = (userId: number, page?: number | undefined) => this.postNuke({uid: userId, page, __act: 'list_folder'})
        .then(res => res[0].map(buildFavorFolder))
    // 修改收藏夹
    folderModify = (folderId: number, name: string, isPublic: boolean) => this.postNuke({
        folder: folderId, name, opt: isPublic ? 1 : 0, __act: 'modify_folder'
    })
    // 从收藏夹内删除帖子, favorId 为 TopicInfo.favorId
    topicDelete = (folderId: number, favorId: string[]) => this.postNuke({
        folder: folderId, __act: 'del', action: 'del', tidarray: favorId.join(',')
    })
    // 添加帖子到收藏夹, folderId 填 -1 时代表收藏到一个新收藏夹（新收藏夹将会是新的默认收藏夹）
    topicAdd = (folderId: number, tid: number, pid?: number | undefined) => this.postNuke({
        folder: folderId, __act: 'add', action: 'add', tid, pid
    })

    postNuke = (params: any) => this.instance.post("nuke.php", {
        __lib: "topic_favor_v2",
        ...params, __output: 11,
    }).then(res => res.data.data)

}